home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln0985.arc
/
CROSSTH.LTG
< prev
next >
Wrap
Text File
|
1986-02-27
|
6KB
|
200 lines
CrossThoughts September
Listings
Listinτá 1«á
PP╠á codσ fo≥ clippinτ algorithφ usinτ thσ ninσ screeεá region≤ ì
method.
Screeεá limit≤á arσá Xmiε t∩ Xma° fo≥ thσ ╪ axi≤ anΣ Ymiε t∩ Yma° iεá thσá ┘ ì
axis.
TYPE Video_Code = (Center, Left, Right, Top, Bottom)
Screen_Video = RECORD XL, YL : Video_Code END
FUNCTION ScreenLoc(X, Y : real) return Screen_Code
A : Screen_Code
BEGIN
A.XL = Center; A.YL = Center
IF X < Xmin THEN A.XL = Left END IF
IF X > Xmax THEN A.XL = Right END IF
IF Y < Ymin THEN A.YL = Bottom END IF
IF Y > Ymax THEN A.YL = Top END IF
ScreenLoc = A
END ScreenLoc
PROCEDURE ClipLine(Xb, Yb, Xf, Yf : real)
PROCEDURE AdjustLine(Loc : Screen_Code) return BOOLEAN
BEGIN
IF Loc has Left code THEN X = Xmin; Calculate clipped Y for Xmin END IF
IF Loc has Right code THEN X = Xmax; Calculate clipped Y for Xmax END IF
IF Loc has Bottom code THEN Y = Ymin; Calculate clipped X for Ymin END IF
IF Loc has Top code THEN Y = Ymax; Calculate clipped X for Ymax END IF
IF Loc = Loc1 THEN Xb = X; Yb = Y ELSE Xf = X; Yf = Y END IF
IF clipping edge is successful THEN AdjustLine = TRUE
ELSE AdjustLine = FALSE
END AdjustLine
BEGIN
Loc1 = ScreenLoc(Xb, Yb); Loc2 = ScreenLoc(Xf, Yf)
Total_Visible_Flag = (Loc▒.XL = Center) AND (Loc1.YL = Center) AND
(Loc2.XL = Center) AND (Loc2.YL = Center)
IF Not Total_Visible_Flag
THEN -- Attempt to determine if the line is trivially outside
Conditon_Y1 = Loc1.YL = Bottom AND Loc2.YL = Bottom
Conditon_Y1 = Loc1.YL = Top AND Loc2.YL = Top
Conditon_X1 = Loc1.XL = Left AND Loc2.XL = Left
Conditon_X2 = Loc1.XL = Right AND Loc2.XL = Rightè Partial_Visible_Flag = NOT ( Condition_X1 OR Condition_X2
OR Condition_Y1 OR Condition_Y2)
ELSE Partial_Visible_Flag = FALSE
END IF
IF Partial_Visible_Flag AND (NOT Total_Visible_Flag)
THE╬
OK = TRUE
IF NOT (Loc▒.XL = Center) AND (Loc1.YL = Center))
THEN OK = AdjustLine(Loc1) END IF
IF NOT (Loc2.XL = Center) AND (Loc2.YL = Center)) AND OK
THEN OK = AdjustLine(Loc2) END IF
Total_Visible_Flag = OK
END IF
IF Total_Visible_Flag THEN Draw line (Xb,Yb),(Xf,Yf)
END ClipLine
Listinτá 2«á
PP╠ codσ fo≥ calculating Bezier curve and performing 2D plots.
FUNCTION Bezier(U : real; X : ARRAY [1..N] OF real) return real
-- The "!" symbol is used to indicate the factorial
-- The "X" array represent the control points.
-- U is the Bezier argument.
BEGIN
INITIALIZE: SumX = 0;
LOOP
BEGIN For i = 0 to N
SumX += [N! / i! (n - i)!] * U^i * (1 - U)^(N - 1) * X[I]
END LOOP
TERMINATE: None
return( SumX )
END Bezier
PROCEDURE Draw_Bezier(X, Y : ARRAY [1..N] OF real;
Start, Finish, Step : real)
BEGIN
INITIALIZE: Read X and Y array; Initialize screen
U = Start
LOOP
BEGIN IF U > Finish THEN EXIT END IF
Xplot = Bezier(U,X); Yplot = Bezier(U,Y);
IF U = Start THEN Plot(Xplot,Yplot)
ELSE Moveto(Xplot,Yplot)
END IF
U += Step
END LOOP
TERMINATE: None
END Draw_Bezierè
Listinτá3.
PPL code for non-periodic B-splines.
FUNCTION Knot(J : integer) return integer
BEGIN
CASE j
WHEN < k => return (0)
WHEN (>= k) AND (<= n) => return (j - k + 1)
OTHERWISE return(n - k + 2)
END CASE
END KNot
FUNCTION Compose(i, k : integer; x : real) return real
BEGIN
IF k = 1
THEN
y = 0
IF (Knot(i) <= x) AND (x < Knot(i+1)) THEN y = 1 END IF
ELSE
y = 0
t = Knot(i + k - 1) - Knot(i)
IF t <> 0 THEN y = (x - Knot(i)) * COmpose(i,k-1,x)/t END IF
t = Knot(i+k) - Knot(i+1)
IF t <> 0 THEN y += Knot(i+k) - x)*Compose(i+1,k-1,x)/t
END IF
return (y)
END Compose
PROCEDURE Draw_Spline(X, Y : ARRAY [1..N] OF real;
N, K : integer;
U : real)
BEGIN
INITIALIZE: Read X and Y array; Initialize screen
Xplot = o; Yplot = 0
LOOP
BEGIN For i = 0 to N
V = Compose(i,K,U)
Xplot += V * X[i]; Yplot += V * Y[i]
IF i = 0 THEN Plot(Xplot,Yplot)
ELSE Moveto(Xplot,Yplot)
END IF
END LOOP
TERMINATE: None
END Draw_Spline
è Figure 2.
Equations for basic shape manipulations.
Translation:
X' = X + Dx X
Y' = Y + Dy Y
where Dx and Dy are the displacement in the X
and Y dimension, respectively.
Rotation:
X' = X cos(A) + y sin(A)
Y' = -X sin(A) + Y cos(A)
where A = Angle of clockwise rotation about the origin.
Scaling:
X' = Sx X
Y' = Sy Y
wherσ S° anΣ S∙ arσ thσ scalinτ factor≤ fo≥
X and Y dimension, respectively.
Reflection:
X' = - X (around Y axis)
Y' = - Y (around X axis)
Shear:
X' = X + S X Y' = Y (X shear)
X' = X Y' = Y + S Y (Y shear)
where S = shear factor.